import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class BiliBiliDownloads {

    public static void main(String[] args) throws IOException {
        final String videoId = "BV12q4y147e4";
        // 页面
        String url = String.format("https://www.bilibili.com/video/%s", videoId);
        // 有多少集
        List<VideoInfo> list = getVideoInfoList(videoId);
        System.out.println();
    }

    private static List<VideoInfo> getVideoInfoList(String videoId) {
        String page = String.format("https://api.bilibili.com/x/player/pagelist?bvid=%s&jsonp=jsonp", videoId);
        HttpRequest get = HttpUtil.createGet(page);
        JSONArray data = JSONObject.parseObject(get.execute().body()).getJSONArray("data");
        List<VideoInfo> res = new ArrayList<>(data.size());
        for (Object datum : data) {
            JSONObject item = (JSONObject) datum;
            VideoInfo videoInfo = item.toJavaObject(VideoInfo.class);
            res.add(videoInfo);
        }
        return res;
    }


}

@Getter
@Setter
class Dimension {
    private Integer width;
    private Integer height;
    private Integer rotate;
}

@Getter
@Setter
class VideoInfo {
    private Integer cid;
    private Integer page;
    private String from;
    private String part;
    private Integer duration;
    private String vid;
    private String weblink;
    private Dimension dimension;
}
